Logistic Regression
Logistic regression for high income countries
grp = income_grp[1]
dat2 <- get_data(dat, grp)
fit <- nls(IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 85.8351 0.9320 92.10 <2e-16 ***
## xmid 2004.7754 0.1508 13291.23 <2e-16 ***
## scal 3.8719 0.1144 33.84 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.44 on 2142 degrees of freedom
##
## Number of iterations to convergence: 4
## Achieved convergence tolerance: 8.016e-06
R2nls(fit)
## $PseudoR2
## [1] 0.8470138
##
## $R2
## [1] 0.8012239
pyear <- seq(min(dat2$year), 2036, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,100),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 2), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for upper middle income countries
grp = income_grp[4]
dat2 <- get_data(dat, grp)
fit <- nls(IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 88.4304 3.8442 23.00 <2e-16 ***
## xmid 2013.6320 0.4798 4196.40 <2e-16 ***
## scal 4.6477 0.1970 23.59 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.794 on 1501 degrees of freedom
##
## Number of iterations to convergence: 3
## Achieved convergence tolerance: 5.134e-06
R2nls(fit)
## $PseudoR2
## [1] 0.8406408
##
## $R2
## [1] 0.816197
pyear <- seq(min(dat2$year), 2050, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,100),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 4), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for lower middle income countries
grp = income_grp[3]
dat2 <- get_data(dat, grp)
fit <- nls(IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 92.8126 15.1584 6.123 1.16e-09 ***
## xmid 2019.4656 1.4861 1358.932 < 2e-16 ***
## scal 4.8565 0.3338 14.551 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.068 on 1592 degrees of freedom
##
## Number of iterations to convergence: 3
## Achieved convergence tolerance: 3.66e-06
R2nls(fit)
## $PseudoR2
## [1] 0.7013986
##
## $R2
## [1] 0.6864479
pyear <- seq(min(dat2$year), 2058, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,100),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 4), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for low income countries
grp = income_grp[2]
dat2 <- get_data(dat, grp)
fit <- nls(IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.NET.USER.ZS ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 63.6779 34.4079 1.851 0.0646 .
## xmid 2023.0045 3.7704 536.554 < 2e-16 ***
## scal 4.3987 0.5267 8.351 3.01e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.084 on 793 degrees of freedom
##
## Number of iterations to convergence: 3
## Achieved convergence tolerance: 8.246e-07
R2nls(fit)
## $PseudoR2
## [1] 0.6503723
##
## $R2
## [1] 0.6461212
pyear <- seq(min(dat2$year), 2100, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,100),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Summary of logistic regression with average values
pyear <- seq(1990, 2100, 1)
plot(x=pyear, y=c(), xlim = c(min(pyear), max(pyear)), ylim=c(0,100),
ylab = "IT.NET.USER.ZS", xlab = "year", xaxt='n',yaxt='n')
axis(1, at = seq(min(pyear),max(pyear), 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
colors <- c("blue","red","orange","green")
names(colors) <- income_grp
for (grp in income_grp) {
gdat <- get_data(dat, grp, is.mean = T)
points(x=gdat$year, y=gdat$IT.NET.USER.ZS, pch=16, col=colors[grp], xaxt='n', yaxt='n', cex=0.75)
matlines(pyear, predict(smdls[[grp]], newdata=list(year=pyear), interval="confidence"), lwd=1)
}
legend("bottomright", legend=c("high income","low income","lower middle income","upper middle income"),
col=colors, lty=0, cex = 0.75, bg = "transparent", pch=16, box.lty=0)

pyear <- seq(1990, 2100, 1)
plot(x=pyear, y=c(), xlim = c(min(pyear), max(pyear)), ylim=c(0,100),
ylab = "IT.NET.USER.ZS", xlab = "year", xaxt='n',yaxt='n')
axis(1, at = seq(min(pyear),max(pyear), 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 100, 5), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
colors <- c("blue","red","orange","green")
names(colors) <- income_grp
for (grp in income_grp) {
gdat <- get_data(dat, grp, is.mean = F)
points(x=gdat$year, y=gdat$IT.NET.USER.ZS, pch=16, col=colors[grp], xaxt='n', yaxt='n', cex=0.25)
matlines(pyear, col = colors[grp], predict(smdls[[grp]], newdata=list(year=pyear), interval="confidence"), lwd=1)
}
legend("bottomright", legend=c("high income","low income","lower middle income","upper middle income"),
col=colors, lty=0, cex = 0.75, bg = "transparent", pch=16, box.lty=0)
